//
//  NewEventTextViewCell.swift
//  YOKO
//
//  Created by Zoe_G on 16/5/22.
//  Copyright © 2016年 15Tec. All rights reserved.
//

import UIKit

class NewEventTextViewCell: NewEventViewBasicCell {

    @IBOutlet weak var textView: UITextView!
    @IBOutlet weak var underLineView: UIView!
    @IBOutlet weak var textViewHeightConstraint: NSLayoutConstraint!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        
        textView.textContainerInset = UIEdgeInsets(top: 3, left: -3, bottom: 0, right: -2)
        notify.addObserverForName(UITextViewTextDidChangeNotification, object: textView, queue: nil, usingBlock: { _ in
            if self.textView.text == "" {
                self.underLineView.backgroundColor = YOKOColor.backImageColor
//                self.iconView?.highlighted = false
                self.textView.backgroundColor = UIColor.clearColor()
            }else {
                self.textViewHeightConstraint.constant = self.heightOfDescriptionTextView()
                self.underLineView.backgroundColor = YOKOColor.TypeColors[1]
//                self.iconView?.highlighted = true
                self.textView.backgroundColor = UIColor.whiteColor()
            }
            
        })
    }
    
    override func drawRect(rect: CGRect) {
        super.drawRect(rect)
        
    }
    
    func heightOfDescriptionTextView () -> CGFloat {
        var textHeight = NSString(string: self.textView.text).boundingRectWithSize(CGSizeMake(self.textView.bounds.width, 9999), options: .UsesLineFragmentOrigin, attributes: [NSFontAttributeName: UIFont.systemFontOfSize(16.0)], context: nil).size.height
        
        //改变cell高度
        textHeight = textHeight > 30 ? textHeight+10 : 30
        
        self.textViewCellHeight = CGFloat(Int(textHeight))+20
        
        return textHeight
    }

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
